<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script type="text/javascript" src="/javascripts/jquery-3.1.1.js"></script>

    <script type="text/javascript">
        function Plugin(index) {
            return document.getElementById('plugin' + index);
        }
        function addEvent(obj, name, func) {
            if (obj.attachEvent && obj.addEventListener == undefined) {
                name = name.toLowerCase().replace(/on/, '');
                obj.attachEvent('on' + name, func);
            } else {
                obj.addEventListener(name, func, false);
            }
        }
        function OnStart() {
            //alert("正在播放");
        }

        function OnStop(toBeContinued) {
            //alert("已停止");
        }
        function OnPause(nReason) {
            /*
             if (nReason == 0)
             alert("暂停");
             else if (nReason == 1)
             alert("正在缓冲...");
             else if (nReason == 2)
             alert("正在搜索...");*/
        }
        function OnResize(nWidth, nHeight) {
            //alert("宽度:"+nWidth+"/高度:"+nHeight);
        }
        function OnError(nErrorType, nErrorID) {
            //alert("类型:"+nWidth+"/错误码:"+nHeight);
        }
        function createObject(length) {
            for (var i = 0; i < length; ++i) {
                var _object = document.createElement('object');
                _object.type = "application/x-umsplayer";
                _object.width = "100%";
                _object.height = "100%";
                _object.id = "plugin" + i;
                var param = document.createElement('param');
                param.name = 'onload';
                param.value = 'pluginLoaded';
                // _object.appendChild(param);

                // $('body').append(_object)
                document.body.appendChild(_object);
                $(_object).on('load', function () {
                    debugger
                })
                // (function(i){
                //     setTimeout(function(){
                //         pluginLoaded(i);
                //     }, 100)
                // })(i)
                // _object.value = pluginLoaded(i)
            }
        }
        function addEvents(index) {
            addEvent(Plugin(index), 'OnStart', OnStart);
            addEvent(Plugin(index), 'OnStop', OnStop);
            addEvent(Plugin(index), 'OnPause', OnPause);
            addEvent(Plugin(index), 'OnResize', OnResize);
            addEvent(Plugin(index), 'OnError', OnError);
        }
        function playDemo(index, id) {
            Plugin(index).UseMediaServer('115.236.100.146:5119');
            Plugin(index).UseTCP();
            Plugin(index).UseLiveAlias(id);
            Plugin(index).Play();
        }
        function pluginLoaded(index) {
            for (var i = 0; i < window.umsUrls.length; ++i) {
                // debugger
                // console.log(index)
                addEvents(i);
                playDemo(i, umsUrls[i]);
            }
        }
        function changeSize() {
            /*
             if (plugin().width==704){
             plugin().width = 352;
             plugin().height = 288;
             } else {
             plugin().width = 704;
             plugin().height = 576;
             }*/
        }
    </script>
</head>

<body>
    <!-- 
    <object id="plugin0" type="application/x-umsplayer" height="100%" width="100%">
        <param name="onload" value="pluginLoaded">
    </object>
    <object id="plugin1" type="application/x-umsplayer" height="100%" width="100%">
        <param name="onload" value="pluginLoaded">
    </object> -->
    <script>
        var url = window.location.href;
        var umsUrls = url.substr(url.indexOf("=") + 1);
        window.umsUrls = umsUrls.split(';');
        createObject(window.umsUrls.length)
    </script>
    <script>
        window.onload = function () {
            pluginLoaded();
        }
    </script>
</body>

</html>